import {getAllSociety,addNewSociety,delSociety} from "@/api/society";

const state = {
  societyInfo: {},
}

const mutations = {
  GET_INFO: (state, data) => {
    state.societyInfo = data;
  },
}

const actions = {
  getInfo({commit, state}, data) {
    return new Promise((resolve, reject) => {
      getAllSociety(data.pageNo, data.limit).then(response => {
        if (response.code === 200) {
          commit('GET_INFO', response.data)
        }
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 添加新社团
  async addNewSociety({commit}, societyName) {
    let result = await addNewSociety(societyName);
    if (result.code === 200){
      return 'OK'
    }
  },
  // 删除社团
  async delSociety(_,ids){
    let response = await delSociety(ids);
    if (response.code === 200){
      return 'OK'
    }
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

